#更新需求单信息
import sys
sys.path.append("..")
import json
from flask import request
from db_client import *
import datetime

def update_demand():
    #更新需求单信息
    token = request.headers.get('token')
    flag, right = token_client.check_token(token)
    if not flag:
        t = {
            'state': 'false',
            'msg': '更新失败'
        }
        return json.dumps(t, ensure_ascii=False)
    else:
        data = json.loads(request.get_data())
        _id = data['id']
        dept = data['department']
        count = data['count']
        time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        flag2 = mysql_client.update_demand1(_id, dept, count, time)
        if flag2:
            t = {
                'state': 'true',
                'msg': 'success'
            }
            return json.dumps(t, ensure_ascii=False)
        else:
            t = {
                'state': 'flase',
                'msg': '更新失败'
            }
            return json.dumps(t, ensure_ascii=False)
